﻿Imports System.Windows.Data

Public Class Control2
	Inherits Control

	Public Sub New()
		MyBase.DefaultStyleKey = GetType(Control2)
	End Sub

#Region " TextProperty Dependency Property "

#Region " Text Property "

	Public Property Text() As String
		Get
			Return DirectCast(GetValue(TextProperty), String)
		End Get
		Set(ByVal value As String)
			' Do not set the dependency property if there is something data bound to the property as this will distroy the property binding.
			Dim bindingExpression As BindingExpressionBase = TryCast(ReadLocalValue(Control2.TextProperty), BindingExpressionBase)
			If bindingExpression Is Nothing Then SetValue(TextProperty, value)
		End Set
	End Property

#End Region

#Region " Text Dependency Property "

	Public Shared ReadOnly TextProperty As DependencyProperty = DependencyProperty.Register("Text", GetType(String), GetType(Control2), New PropertyMetadata("Control 2", AddressOf OnTextPropertyChanged))

#End Region

#Region " Text Property Changed CallBack "

	Private Shared Sub OnTextPropertyChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
		Dim source As Control2 = TryCast(d, Control2)
		If source Is Nothing Then Throw New ArgumentException("source is not an instance of Control2!")
		source.OnTextChanged(d, e)
	End Sub

#End Region

#Region " Text Overridable Property Changed "

	Protected Overridable Sub OnTextChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
		' Provide validation here. Developer may override this.
		RaiseTextChangedEvent(d, e)
	End Sub

#End Region

#Region " Raise Text Routed Event "

	Protected Overridable Sub RaiseTextChangedEvent(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
		' Do nothing except raise the event here.  Developer may override this and decide not to raise the event.
		RaiseEvent TextChanged(d, e)
	End Sub

#End Region

#Region " Text Routed Event "

	Public Event TextChanged As PropertyChangedCallback

#End Region

#End Region


End Class